package cc.bluemc.modules.weixin.action;


import cc.bluemc.modules.adminUser.entity.AdminUser;
import cc.bluemc.modules.weixin.entity.WxuserEntity;
import cc.bluemc.modules.weixin.service.WxuserService;
import cc.bluemc.platform.comm.BaseAction;
import cc.bluemc.platform.comm.DataTablesPagination;
import cc.bluemc.platform.jdbctemplatetool.exception.NoColumnAnnotationFoundException;
import cc.bluemc.platform.jdbctemplatetool.exception.NoIdAnnotationFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/wx3p/manage")
public class WxUserAction extends BaseAction{
	@Autowired
	private WxuserService bvcWxuserService;
	/**
	*表单页面
	*/
	@RequestMapping("form")
	public String addForm(Long id,Model model) throws NoColumnAnnotationFoundException, NoIdAnnotationFoundException {
		if(null!=id){
			WxuserEntity bvcWxuser= bvcWxuserService.get(id);
			model.addAttribute("bean", bvcWxuser);
		}
		return "bvcWxuser/web/form";
	}

	/**
	 * 同步微信用户数据
	 */
	@ResponseBody
	@RequestMapping("{appId:.+}/user/syncWxUser")
	public void syncWxUser(@PathVariable("appId")String appId) throws Exception {
		AdminUser adminUser = getAdminUser();
		bvcWxuserService.deleUserByAppId(appId);
		bvcWxuserService.syncWxUser(appId,adminUser.getId(),null);
	}
	/**
	 * 列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping("{appId:.+}/user/list")
	public String list(@PathVariable("appId")String appId,Model model){
		model.addAttribute("appId",appId);
		return "weixin/wx3p/userList";
	}
	/**
	 * 分布查询数据
	 * @return
	 */
	@ResponseBody
	@RequestMapping("{appId:.+}/user/pageList")
	public DataTablesPagination listPage(@PathVariable("appId")String appId,DataTablesPagination pageable){
		return  bvcWxuserService.getListOfPage(appId,pageable);
	}

}
